package main

import (
	_ "bootstrap/config-yaml/yaml"
	"bootstrap/global/config"
	"fmt"
)

type Bootstrap struct {
	Bootstrap struct {
		Name    string `name:"name"`
		Version string `name:"version"`
	} `name:"bootstrap"`
	Author Author `name:"author"`
}

type Author struct {
	Name           string `name:"name"`
	YearsOfWorking int    `name:"years-of-working"`
	Age            string `name:"age" default:"18"`
}

func main() {
	err := config.InitGlobalInstance("yaml", "resource/app.yaml")
	if err != nil {
		fmt.Printf("init yaml config faield: %v\n", err)
		return
	}
	if name, ok := config.Get("bootstrap.name"); ok {
		fmt.Printf("bootstrap name: %v\n", name)
	} else {
		fmt.Println("not found bootstrap.name")
	}
	if version, ok := config.Get("bootstrap.version"); ok {
		fmt.Printf("bootstrap version: %v\n", version)
	} else {
		fmt.Println("not found bootstrap.version")
	}
	var bootstrap Bootstrap
	if err := config.Resolve("", &bootstrap); err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Printf("resolve bootstrap: %v\n", bootstrap)
	}

	var author Author
	if err := config.Resolve("author", &author); err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Printf("resolve author: %v\n", author)
	}
}
